package com.zxd.util;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

public class SpringHandler {
	private Connection conn;
	private DataSource dataSource;
	private static WebApplicationContext applicationContext;
	static{
		applicationContext = ContextLoader.getCurrentWebApplicationContext();
	}
	public SpringHandler() {
		dataSource = (DataSource)applicationContext.getBean("dataSource");
		try {
			conn = dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public static SpringHandler newInstance(){
		return new SpringHandler();
	}
	public Connection getConnection(){
		return conn;
	}
	public static WebApplicationContext getApplicationContext(){
		return applicationContext;
	}
}
